//
//  PingTime.m
//  CoinEgg_App
//
//  Created by tjl on 2018/7/9.
//  Copyright © 2018年 tjl. All rights reserved.
//

#import "PingTime.h"

@implementation PingTime

- (instancetype)initWithHostName:(NSString *)host time:(void (^)(int))timeBlock {
    
    if (self == [super init]) {
        
        _timeBlock = timeBlock;
        //ping
        self.pingTester = [[WHPingTester alloc] initWithHostName:host];
        self.pingTester.delegate = self;
        [self.pingTester startPing];
        
    }
    return self;
    
}

#pragma mark ping的回调
- (void)didPingSucccessWithTime:(float)time withError:(NSError *)error
{
    if(error){
        NSLog(@"网络有问题");
        //TODO://tjl  此处有回调，可设置-1
        _timeBlock(-1);
    }else{
        _timeBlock((int)time);
    }
}

@end
